package daoImpl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import dao.UsersDao;
import entlty.Users;
import utils.BaseDao;

public class UserDaoImpl extends BaseDao implements UsersDao{

	@Override
	public int tianjia(Users u) {
		String sql="insert into users values(null,?,?)";
		int i=super.exeUpdate(sql, u.getUname(),u.getPwd());
		return i;
	}

	@Override
	public Users getAll(String uname,String pwd) {
		Users s=null;
		String sql="select * from users where uname=? and pwd=?";
		ResultSet rs=super.exeQuery(sql,uname,pwd);
		try {
			while(rs.next()){
				s=new Users(rs.getInt(1),rs.getString(2),rs.getString(3));
				
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return s;
	}

	@Override
	public List<Users> getzh() {
		List<Users> list=new ArrayList<>();
		String sql="select * from users";
		ResultSet rs=super.exeQuery(sql);
		try {
			while(rs.next()){
				Users us=new Users(rs.getInt(1),rs.getString(2),rs.getString(3));
				list.add(us);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list;
	}

}
